# 18. 分割均衡字符串

18 18-1

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
rl.on('line', function(str)) {
    let ans = 0;
    let count = 0;
    for(let i=0; i<str.length; i++) {
        if (str[i] === 'X') {
            count++;
        } else {
            count--;
        }
        if (count === 0) {
            ans++;
        }
    }
    console.log(ans);
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21